﻿using XCode;
using Zdap.Common;
using Zdap.XCode.Service;

namespace Datav.Design.Service
{
    /// <summary>
    ///
    /// </summary>
    public class LimitConfigService : BaseService<LimitConfig, LimitConfigModel>, ILimitConfigService
    {
        /// <summary>
        ///
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public override async ValueTask<ResponseContext<long>> Save(LimitConfigModel dto, UserTicket user)
        {
            var limit = await LimitConfig.FindAsync(LimitConfig._.TenantId == dto.TenantId & LimitConfig._.IsDelete == 0);
            if (limit != null)
            {
                dto.Id = limit.Id;
            }
            return await base.Save(dto, user);
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public async ValueTask<ResponseContext<long>> OpenSchoolLimit(AuthorizeDto dto, UserTicket user)
        {
            var limit = await LimitConfig.FindAsync(LimitConfig._.TenantId == dto.TenantId & LimitConfig._.IsDelete == 0);
            var limtModel = new LimitConfigModel();
            if (limit != null)
            {
                limtModel.Id = limit.Id;
            }
            var userTeachers = new List<WorldDesignUser>();

            //dto.YssxUsers.ForEach(s =>
            //{
            //    var item = s.MapTo<WorldDesignUser>();
            //    userTeachers.Add(item);
            //});
            userTeachers.Insert();
            return await base.Save(limtModel, user);
        }
    }
}